package ru.maxmatveev.dyndao.demo.dao;

import ru.maxmatveev.dyndao.*;
import ru.maxmatveev.dyndao.demo.model.Child;
import ru.maxmatveev.dyndao.demo.model.Parent;

import java.util.Collection;

/**
 * @author Max Matveev
 *         Date: Dec 21, 2008
 *         Time: 11:13:09 PM
 */
public interface ChildDao extends DynamicDao<Child, Long> {
    /**
     * Method getByParentIdPaginated ...
     *
     * @param parrentId  parent entity ID
     * @param pagination pagination parameters
     * @return Collection<Child>
     */
    Collection<Child> getByParentIdPaginated(
            @Restriction.ParentId(parentClass = Parent.class, fieldName = "children") Long parrentId,
            @Pagination.Paginate Pagination pagination
    );

    /**
     * Method getCountByParentId ...
     *
     * @param parrentId parent entity id
     * @return count
     */
    @Count
    Integer getCountByParentId(
            @Restriction.ParentId(parentClass = Parent.class, fieldName = "children") Long parrentId
    );

    Child getByIdAndName(@Restriction.Field(fieldName = "id", comparison = Restriction.Comparison.EQUALS) Long id,
                         @Restriction.Field(fieldName = "name", comparison = Restriction.Comparison.EQUALS) String name);
    
    /**
     * Method getByParentPaginatedAndSortedByName ...
     *
     * @param parentRestriction parent choice restriction
     * @param pagination        pagination parameters
     * @return Collection<Child>
     */
    @Ordering.Field(fieldName = "name")
    Collection<Child> getByParentPaginatedAndSortedByName(
            @Restriction.Parent(parentClass = Parent.class, fieldName = "children") Restriction parentRestriction,
            @Pagination.Paginate Pagination pagination
    );
}
